/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package se.kth.lwr.jeat.utils;

import javax.measure.quantity.Length;
import javax.measure.quantity.Area;
import javax.measure.quantity.Quantity;
import javax.measure.quantity.Volume;
import org.jscience.physics.amount.Amount;
import se.kth.lwr.jeat.core.AmountDataSource;
import se.kth.lwr.jeat.core.AmountFunction;
import se.kth.lwr.jeat.core.DataSource;

/**
 * A class that express a Volume as an {@link AmountDataSource}. Raw Amounts
 * passed to this class constructors are wrapped as dataSources
 *
 * @author davidev
 */
public class AmountVolume {

    private AmountDataSource width;
    private AmountDataSource height;
    private AmountDataSource depth;
    private AmountDataSource area;

    /**
     * Creates an Amount volume by values of width, height and length.
     *
     * @param width
     * @param height
     * @param depth
     */
    public AmountVolume(Amount<Length> width, Amount<Length> height, Amount<Length> depth) {

        this.width = wrapDimData("width", width);
        this.height = wrapDimData("height", height);
        this.depth = wrapDimData("depth", depth);
    }

    /**
     * Creates an Amount volume by values of area and depth
     *
     * @param area
     * @param depth
     */
    public AmountVolume(Amount<Area> area, Amount<Length> depth) {
        this.depth = wrapDimData("depth", depth);
        this.area = wrapDimData("area", area);

    }

    protected AmountDataSource <? extends Quantity> wrapDimData(String dimension, Amount<? extends Quantity> amount) {

        return new AmountDataSource<>("dimension",
                dimension + " of element in this context",
                amount);

    }

    /**
     *
     * @return the volume expressed as an AmountFunction
     */
    public AmountFunction getVolume() {
        if (area == null) {
            return new AmountFunction().multiply(width).multiply(height).multiply(depth);
        } else {
            return new AmountFunction().multiply(area).multiply(depth);
        }

    }
}
